package codegen.ui.jung;

import edu.uci.ics.jung.algorithms.layout.Layout;
import edu.uci.ics.jung.visualization.RenderContext;
import edu.uci.ics.jung.visualization.renderers.Renderer;
import edu.uci.ics.jung.visualization.transform.shape.GraphicsDecorator;
import groovy.swing.j2d.GraphicsContext;
import edu.uci.ics.jung.graph.Graph;
import edu.uci.ics.jung.graph.util.Context;
import codegen.groovy.graphnetwork.graphics.*;
        
public class GroovyGraphicsRenderer<V, E> implements Renderer.Vertex<V, E> {

    GraphicsContext context = new GraphicsContext();

    public GroovyGraphicsRenderer() {
    }

    public void paintVertex(RenderContext<V, E> rc, Layout<V, E> layout, V v) {
        Graph<V, E> graph = layout.getGraph();
        if (rc.getVertexIncludePredicate().evaluate(Context.<Graph<V, E>, V>getInstance(graph, v))) {
            paintVertex2(rc, layout, v);
        }

    }

    protected void paintVertex2(RenderContext<V, E> rc, Layout<V, E> layout, V v) {
        GraphicsDecorator gd = rc.getGraphicsContext();
        context.setG(gd.getDelegate());
        NodeDisplay nodeDisplay = new NodeDisplay(v, rc, layout);
        nodeDisplay.getNodeShape().execute(context);
    }
}
